using Animoso.Domain.Data;
using StructureMap;
using System.ComponentModel.DataAnnotations;

namespace Animoso.Domain
{
    public class Sponsor : DomainObject
    {
        public string Name { get; set; }
        public string Link { get; set; }

        [CustomValidation(typeof(Sponsor), "ValidateLocation")]
        public ImageLocation ImageLocation { get; set; }

        public string Picture { get; set; }
        public bool Active { get; set; }

        public static ValidationResult ValidateLocation(ImageLocation imageLocation, ValidationContext context)
        {
            ISponsorRepository sponsorRepository = ObjectFactory.GetInstance<ISponsorRepository>();

            if(imageLocation == ImageLocation.Footer)
            {
                if (sponsorRepository.GetSponsorsByImageLocation(imageLocation) == null)
                {
                    return ValidationResult.Success;
                }
            }
            if(imageLocation == ImageLocation.Carousel)
            {
                return ValidationResult.Success;
            }

            return new ValidationResult("Er bestaat al sponsor met die locatie");
        }
    }

    public enum ImageLocation
    {
        Footer,
        Carousel
    }
}